/* 使用jquery工具文件 */

/* Form表单数据转对象，再转JSON
 * 用法参考：
 var formData = $('#Form表单ID').serializeObject();
 //删除某个属性
 delete formData.parentId;
 //添加某个子对象，让表单支持二级对象
 formData.parent = {
 id : 对象值
 };
 //对象转JSON
 JSON.stringify(formData)
 */
$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [ o[this.name] ];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};

function parseParam(param, key) {
	var paramStr = "";
	if (param instanceof String || param instanceof Number || param instanceof Boolean) {
		paramStr += "&" + key + "=" + encodeURIComponent(param);
	} else {
		$.each(param, function(i) {
			var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
			paramStr += '&' + parseParam(this, k);
		});
	}
	return paramStr.substr(1);
};